//
//  SKUDetailWatchScrNewV.m
//  ZITHER
//
//  Created by weixin on 2018/9/2.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailWatchScrNewV.h"

@implementation SKUDetailWatchScrNewV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration] ;
        [self setUI];
        [self setMasonry];
    }
    return self;
}

-(void)defaultConfiguration{
    self.delegate = self;
    self.bounces = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.contentSize = CGSizeMake(0, 1300);//不确定
}

-(void)setUI{
    [self addSubview:self.TopscroView];
    
    [self addSubview:self.pageController];
    
    [self addSubview:self.UserImageS];
    
    [self addSubview:self.ScrPublicV];
    
    [self addSubview:self.GraphV];
}

-(void)setMasonry{
    [self.TopscroView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(self).offset(0);
        make.width.mas_equalTo(kScreenW);
        make.height.mas_equalTo(190);
    }];
    
    //    [self addSubview:self.TopscroView.pageController];

    [self.UserImageS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.TopscroView.mas_bottom).offset(0);
        make.left.width.mas_equalTo(self).offset(0);
        make.height.mas_equalTo(200);
    }];

    [self.ScrPublicV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.UserImageS.mas_bottom).offset(0);
        make.left.width.mas_equalTo(self).offset(0);
        make.bottom.mas_equalTo(self.ScrPublicV.viewBorderlines.mas_bottom).offset(0);

    }];
    

    [self.GraphV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.ScrPublicV.mas_bottom).offset(0);
        make.left.width.mas_equalTo(self).offset(0);
        make.height.mas_equalTo(600);
    }];
    
    [self.pageController mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.centerX).offset(0);
        make.bottom.mas_equalTo(self.TopscroView.mas_bottom).offset(0);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    
    [self layoutIfNeeded];
    self.contentSize = CGSizeMake(0,CGRectGetMaxY(self.GraphV.frame));
//    NSLog(@"%@", self.scrollView);
    
}

-(MainDetailTopScrollNewV *)TopscroView{
    if (!_TopscroView) {
        _TopscroView = [[MainDetailTopScrollNewV alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    }
    return _TopscroView;
}

-(SKUDefultUserImageNewV *)UserImageS{
    if (!_UserImageS) {
        _UserImageS = [[SKUDefultUserImageNewV alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 200)];
    }
    return _UserImageS;
}

-(SKUDefultScrPublicNewV *)ScrPublicV{
    if (!_ScrPublicV) {
        _ScrPublicV = [[SKUDefultScrPublicNewV alloc]initWithFrame:CGRectMake(15, 0, kScreenW-30, 200)];
    }
    return _ScrPublicV;
}

-(SKUDefultGraphNewV *)GraphV{
    if (!_GraphV) {
        _GraphV = [[SKUDefultGraphNewV alloc]initWithFrame:CGRectMake(0,500, kScreenW, 700)];
//        [_GraphV setBlockUpLoadData:^{
//            if (self.blockUpLoadData) {
//                self.blockUpLoadData();
//            }
//        }];
    }
    return _GraphV;
}

-(void)setModel:(skuDetailModel *)model
{
    _model = model;
    self.TopscroView.model = model;
    self.UserImageS.model = model;
    self.ScrPublicV.model = model;
    self.GraphV.model = model;
    
    if (model.attributes.count>0){
        self.pageController.numberOfPages = 3;
        self.TopscroView.contentSize = CGSizeMake(kScreenW*3,0);

    }else{
        self.pageController.numberOfPages = 2;
        self.TopscroView.contentSize = CGSizeMake(kScreenW*2,0);
    }
    
    if ([self.model.myEnquiryFlag isEqualToString:@"0"]) {
        self.ScrPublicV.hidden = NO;
        [self.ScrPublicV mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.ScrPublicV.viewBorderlines.mas_bottom).offset(0);
        }];
        
    }else if ([self.model.myEnquiryFlag isEqualToString:@"1"]){
        self.ScrPublicV.hidden = YES;
        [self.ScrPublicV mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        
    }else{
        self.ScrPublicV.hidden = NO;
        [self.ScrPublicV mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.ScrPublicV.viewBorderlines.mas_bottom).offset(0);
        }];
    }
    [self layoutIfNeeded];

}


-(UIPageControl *)pageController
{
    if (!_pageController) {
        _pageController = [[UIPageControl alloc] initWithFrame:CGRectMake(0,200 , 80, 30)];
        _pageController.numberOfPages = 2;
        _pageController.currentPage = 1;//滑动是修改显示
        _pageController.currentPageIndicatorTintColor = [UIColor blackColor];
        _pageController.pageIndicatorTintColor = [UIColor RGBColorWithR:224 g:224 b:224];
    }
    return _pageController;
}


@end
